cmake_minimum_required(VERSION 3.21)
project(wayland_test)

set(CMAKE_CXX_STANDARD 17)

set(TARGET_NAME wayland_test)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Wayland REQUIRED)

if (NOT WAYLAND_FOUND)
    message(FATAL_ERROR "Not find Wayland")
endif ()

add_executable(${TARGET_NAME} main.cpp)

target_include_directories(${TARGET_NAME} PRIVATE ${WAYLAND_INCLUDE_DIR})
target_link_libraries(${TARGET_NAME} ${WAYLAND_LIBRARIES})

if (UNIX AND NOT APPLE AND NOT ANDROID)
    # Threads
    find_package(Threads)
    target_link_libraries(${TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
endif ()

if (UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID)
    find_library(RT_LIBRARY rt)
    mark_as_advanced(RT_LIBRARY)
    if (RT_LIBRARY)
        target_link_libraries(${TARGET_NAME} ${RT_LIBRARY})
    endif ()

    find_library(MATH_LIBRARY m)
    mark_as_advanced(MATH_LIBRARY)
    if (MATH_LIBRARY)
        target_link_libraries(${TARGET_NAME} ${MATH_LIBRARY})
    endif ()

    target_link_libraries(${TARGET_NAME} -latomic)
endif ()
